﻿$(document).on("pageInit", "#clazz-info-detail", function (e, id, page) {
    loadData();
    var clazzId = $(page).find('[name="clazzInfoId"]').val();

    var buttons1 = [
            {
                text: '请选择',
                label: true
            },
            {
                text: '添加学生',
                bold: true,
                onClick: function () {
                    $.router.load('/clazzinfo/createstudent/' + clazzId, true);
                }
            },
            {
                text: '编辑班级',
                bold: true,
                onClick: function () {
                    $.router.load('/clazzinfo/edit/' + clazzId, true);
                }
            }
    ];

    // 加载班级数据
    function loadData() {
        $(page).find("#studentList").empty();

        $.getJSON("/ClazzInfo/GetStudentList/" + $(page).find('[name="clazzInfoId"]').val(), {}, function (response) {
            $.each(response, function (index, item) {
                var frame = $('<li class="item-content item-link"><div class="item-media"><i class="icon icon-f7"></i></div><a href="/student/info/' + item.UserId + '" class="item-inner"><div class="item-title">' + item.RealName + '</div></a> </li>');
                $(page).find("#studentList").append(frame);
            });
        });

        $.getJSON("/ClazzInfo/GetClazzInfo/" + $(page).find('[name="clazzInfoId"]').val(), {}, function (response) {
            $(page).find(".title").html(response.ClazzName);
        });
    }

    // 编辑按钮
    $(page).find("#menu-btn").on("click", function (menuE) {
        e.preventDefault();
        var clazzId = menuE.currentTarget.dataset.clazz;
        var buttons2 = [
         {
             text: '取消',
             bg: 'danger'
         }
        ];
        var groups = [buttons1, buttons2];
        $.actions(groups);
    });
});